package com.foldingleaf.web.controller.banner;

import com.foldingleaf.banner.domain.Banner;
import com.foldingleaf.banner.service.IBannerService;
import com.foldingleaf.common.annotation.Log;
import com.foldingleaf.common.core.controller.BaseController;
import com.foldingleaf.common.core.domain.Result;
import com.foldingleaf.common.core.page.TableDataInfo;
import com.foldingleaf.common.enums.BusinessType;
import com.foldingleaf.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 广告banner图Controller
 * 
 * @author ajian
 * @date 2022-06-22
 */
@Api(value = "/banner/banner", tags = {"广告banner图Controller"})
@RestController
@RequestMapping("/banner/banner")
public class BannerController extends BaseController
{
    @Autowired
    private IBannerService bannerService;

    /**
     * 查询广告banner图列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "Banner", name = "banner", value = "")
    })
    @ApiOperation(value = "查询广告banner图列表", notes = "查询广告banner图列表", httpMethod = "GET")

    @GetMapping("/list")
    public TableDataInfo list(Banner banner)
    {
        startPage();
        List<Banner> list = bannerService.selectBannerList(banner);
        return getDataTable(list);
    }

    /**
     * 导出广告banner图列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "HttpServletResponse", name = "response", value = ""),
            @ApiImplicitParam(paramType = "query", dataType = "Banner", name = "banner", value = "")
    })
    @ApiOperation(value = "导出广告banner图列表", notes = "导出广告banner图列表", httpMethod = "POST")
    @PreAuthorize("@ss.hasPermi('banner:banner:export')")
    @Log(title = "广告banner图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Banner banner)
    {
        List<Banner> list = bannerService.selectBannerList(banner);
        ExcelUtil<Banner> util = new ExcelUtil<Banner>(Banner.class);
        util.exportExcel(response, list, "广告banner图数据");
    }

    /**
     * 获取广告banner图详细信息
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "long", name = "bannerId", value = "")
    })
    @ApiOperation(value = "获取广告banner图详细信息", notes = "获取广告banner图详细信息", httpMethod = "GET")

    @GetMapping(value = "/{bannerId}")
    public Result getInfo(@PathVariable("bannerId") Long bannerId)
    {
        return Result.success(bannerService.selectBannerByBannerId(bannerId));
    }

    /**
     * 新增广告banner图
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Banner", name = "banner", value = "")
    })
    @ApiOperation(value = "新增广告banner图", notes = "新增广告banner图", httpMethod = "POST")
    @PreAuthorize("@ss.hasPermi('banner:banner:add')")
    @Log(title = "广告banner图", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody Banner banner)
    {
        return toAjax(bannerService.insertBanner(banner));
    }

    /**
     * 修改广告banner图
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Banner", name = "banner", value = "")
    })
    @ApiOperation(value = "修改广告banner图", notes = "修改广告banner图", httpMethod = "PUT")
    @PreAuthorize("@ss.hasPermi('banner:banner:edit')")
    @Log(title = "广告banner图", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody Banner banner)
    {
        return toAjax(bannerService.updateBanner(banner));
    }

    /**
     * 删除广告banner图
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "Long[]", name = "bannerIds", value = "")
    })
    @ApiOperation(value = "删除广告banner图", notes = "删除广告banner图", httpMethod = "DELETE")
    @PreAuthorize("@ss.hasPermi('banner:banner:remove')")
    @Log(title = "广告banner图", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bannerIds}")
    public Result remove(@PathVariable Long[] bannerIds)
    {
        return toAjax(bannerService.deleteBannerByBannerIds(bannerIds));
    }
}
